<?php

require_once("scripts/authentication.php");
require_once("scripts/dbconnection.php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
		<title>eLibrary Administration : Books</title>
		<link href="style/defaults.css" rel="stylesheet" type="text/css" media="all" />
		<link href="style/elements.css" rel="stylesheet" type="text/css" media="all" />
		<link href="style/management.css" rel="stylesheet" type="text/css" media="all" />
		
		<script src="js/ajax.js" type="text/javascript"></script>
		<script src="js/book.js" type="text/javascript"></script>
	</head>
	<body>
		
		<div class="header">
			<h1><a href="index.php">eLibrary</a></h1>
			<h3>Administer your library.</h3>
		</div>
		
		<div class="container">
			<h2>Book Management.</h2>
			<div class="column">
				<p class="firstP"></p>
			</div>
			<div class="column">
				<h4>Adding Books</h4>
				<p></p>
			</div>
			<div class="column">
				<h4>Removing Books</h4>
				<p></p>
			</div>
			
			<div class="separator"></div>
			
			<div class="column">
			
			<!-- Begin List of Books -->
			
			<?php
			
				// Get a list of all the books
				$result = mysql_query("SELECT * FROM BOOK");
			
				// Loop through and display the results
				while ($row = mysql_fetch_assoc($result))
				{
					if ($row["AuthorID"] != null)
					{
						// Get the authorName
						$result2 = mysql_query("SELECT AuthorName FROM Author WHERE AuthorID = " . $row["AuthorID"]);
						$authorNameRow = mysql_fetch_assoc($result2);
					}
					else
					{
						$authorNameRow = null;
					}
					
					?>
					
					<div class="bookCol" id="Book_<?php echo $row["BookID"]; ?>"  onclick="showSettings(<?php echo $row["BookID"]; ?>)">
						<span class="callNo"><?php if ($row["CallNo"] != null) { echo $row["CallNo"]; } else { echo "&nbsp;"; } ?></span>
						<span class="title"><?php if ($row["Title"] != null) { echo $row["Title"]; } else { echo "&nbsp;"; } ?></span>
						<span class="author"><?php if ($authorNameRow != null) { echo $authorNameRow["AuthorName"]; } else { echo "None"; } ?></span>
						
						<div class="clear"></div>
						
						<div class="actions hide" id="Book_<?php echo $row["BookID"]; ?>_Actions">
							<span class="edit">Edit</span>
							|
							<span class="remove" onclick="removeAuthor(<?php echo $row["AuthorID"]; ?>, '<?php echo $row["AuthorName"]; ?>')">Remove</span>
						</div>
						
						<div class="clear"></div>
					</div>
					
					<?php
				}
			
			?>
						
			<!-- End List of Books -->
			
			</div>
			
			<div class="clear"></div>
			
		</div>
	</body>
</html>